package com.loong.game2048.server.impl;

import com.loong.game2048.dao.ForumDao;
import com.loong.game2048.dao.UserDao;
import com.loong.game2048.module.User;
import com.loong.game2048.server.UserServer;
import com.loong.game2048.util.FileUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author lyx
 * @date 2020/5/8 22:33
 */
@Service
public class UserServerImpl implements UserServer {

    @Resource
    private UserDao userDao;

    @Override
    public Integer getUserCountById(String openId) {
        return userDao.getCountById(openId);
    }

    @Override
    public User getUserById(String openId) {
        return userDao.getUserById(openId);
    }

    @Override
    public Integer addUser(String openId) {
        if (openId!=null){
            return userDao.addUser(openId);
        }
        return 0;
    }

    @Override
    public Integer updateUserMsg(User user) {
        if (user!=null){
            //删除照片
            FileUtils.deleteFile("static/img/photo/"+userDao.getUserById(user.getOpenId()).getPhoto());
            return userDao.updateUserMsg(user);
        }
        return 0;
    }

    @Override
    public Integer updateUserBackground(User user) {
        FileUtils.deleteFile("static/img/photo/"+userDao.getUserById(user.getOpenId()).getBackground());
        return userDao.updateUserBackground(user);
    }
}
